#!/bin/bash

echo "🧪 cbp2make_ai.exe 功能测试"
echo "================================"

if [ ! -f "bin/cbp2make_ai" ]; then
    echo "❌ 可执行文件不存在"
    exit 1
fi

echo "1. 基本信息测试"
echo "---------------"
./bin/cbp2make_ai --version 2>&1
echo "退出码: $?"

echo ""
echo "2. 帮助信息测试"
echo "---------------"
./bin/cbp2make_ai --help 2>&1 | head -20

echo ""
echo "3. 实际功能测试 - 生成 Makefile"
echo "------------------------------"

# 创建测试项目
cat > test_project.cbp << 'TESTPROJ'
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
    <Option title="Test Project" />
    <Build>
        <Target title="Debug">
            <Option output="bin/debug/test" />
            <Option type="1" />
            <Compiler>
                <Add option="-g" />
                <Add option="-O0" />
            </Compiler>
        </Target>
        <Target title="Release">
            <Option output="bin/release/test" />
            <Option type="1" />
            <Compiler>
                <Add option="-O2" />
            </Compiler>
        </Target>
    </Build>
    <Unit filename="main.cpp" />
    <Unit filename="utils.cpp" />
</Project>
</CodeBlocks_project_file>
TESTPROJ

echo "处理测试项目..."
./bin/cbp2make_ai test_project.cbp 2>&1

if [ -f "makefile" ]; then
    echo "✅ Makefile 生成成功!"
    echo "文件预览:"
    head -30 makefile
    echo "..."
    wc -l makefile
    rm -f makefile
else
    echo "❌ 未生成 Makefile"
fi

rm -f test_project.cbp

echo ""
echo "4. AI 功能标志测试"
echo "------------------"
echo "检查 AI 增强功能是否启用:"
./bin/cbp2make_ai --help 2>&1 | grep -i "ai" || echo "未找到 AI 相关选项"

echo ""
echo "================================"
echo "测试完成"
